import cfg from '../../config';
import { getView } from '../../util/api';
import { formatDate, getCurrDay, randomColor, isArrContain, isArrNoContain, findStr, backPage, getPrevDate, getNextDate, message, closeMsg, getPinYin } from '../../util/aid';

const $ = require('../../lib/kdom');
let _view = require('raw-loader!./user.html');

let _url = '/train/user'; // 流转地址

export default class {
  path = '/train/user$';
  hash = '/train/user';
  title = '用户中心';

  constructor(opt) {
    opt = opt || {};
    this.path = opt.path || this.path;
    this.hash = opt.hash || this.hash;
    this.title = opt.title || this.title;
  }

  // 输出视图
  view(cb) {
    if (!_view) {
      // 静态资源浏览器有缓存,增加时标,强制刷新!
      getView(`${cfg.train.view.user}?t=${(+new Date())}`, '', (rs) => {
        _view = rs;
        cb(null, _view);
      });
    } else
      cb(null, _view);
  }

  // 在已经加载的视图上操作
  bind(dv, params) {
    orderView.onclick = () => {
      $.router.go('/train/order', '', true);
    };
    passengerView.onclick = () => {
      $.router.go('/train/passenger', { url: _url }, true);
    };
    // contactsView.onclick = () => {
    //   $.router.go('/train/contacts', '', true);
    // };
    // orderQueryView.onclick = () => {
    //   $.router.go('/train/order-query', '', true);
    // };
    infoService.onclick = () => {
      $.router.go('/train/info-service', '', true);
    };

    // backPage
    backPage('#pg-train-user', 'backPage', () => {
      $.router.go('/train/home', '', true);
    });
  }

  /*bind*/
}